<?php /* Created on: 5/6/2010 */ ?>
<html>
<body>
<?php
/*
  $waterselect = $_REQUEST['waterway'];
  $tablename = $waterselect;
  $server = "sql.byethost27.org";
  $username = "rockedg1_rockedg";
  $password = "keelwater";
  $database = "rockedg1_tank60";
   print("  River:  $tablename\n");
*/ 
include("connect.php");
$waterselect = $_REQUEST['waterway'];
$tablename = $waterselect;
/*
/*$global_dbh = mysql_connect($hostname, $username, $password)
or die("Could not connect to database");
mysql_select_db($database,$global_dbh)   /*mysql_select_db($db, $global_dbh)
or die("Could not select database");
*/
function display_db_query($query_string, $connection, $header_bool, $table_params) {
	// perform the database query
	$result_id = mysql_query($query_string, $connection)
	or die("display_db_query:" . mysql_error());
	// find out the number of columns in result
	$column_count = mysql_num_fields($result_id)
	or die("display_db_query:" . mysql_error());
	// Here the table attributes from the $table_params variable are added
	print("<TABLE $table_params >\n");
	// optionally print a bold header at top of table
	if($header_bool) {
		print("<TR>");
		for($column_num = 0; $column_num < $column_count; $column_num++) {
			$field_name = mysql_field_name($result_id, $column_num);
			print("<TH>$field_name</TH>");
		}
		print("</TR>\n");
	}
	// print the body of the table
	while($row = mysql_fetch_row($result_id)) {
		print("<TR ALIGN=LEFT VALIGN=TOP>");
		for($column_num = 0; $column_num < $column_count; $column_num++) {
			print("<TD>$row[$column_num]</TD>\n");
		}
		print("</TR>\n");
	}
	print("</TABLE>\n"); 
}

function display_db_table($tablename, $connection, $header_bool, $table_params) {
	$query_string = "SELECT * FROM $tablename ORDER BY `id` ASC LIMIT 0, 30 ";
	display_db_query($query_string, $connection,
	$header_bool, $table_params);
}
?>
<HTML><HEAD><TITLE>Displaying a MySQL table</TITLE></HEAD>
<BODY>
<TABLE border=2 bgcolor=#6699FF bordercolor=#000000 summary=""><TR><TD>
<?php
//In this example the table name to be displayed is  static, but it could be taken from a form
$table = $tablename;

display_db_table($table, $con,TRUE, "border='2'");
?>
</TD></TR></TABLE></BODY></HTML>
</body>
</html>